var site_url=localStorage.getItem("site_url");

$(function () {
    //根据ID获取iframe对象
    var ifr = document.getElementById('admin_right');
    ifr.onload = function() {
        //解决打开高度太高的页面后再打开高度较小页面滚动条不收缩
        ifr.style.height='0px';
        var iDoc = ifr.contentDocument || ifr.document;
        var height = calcPageHeight(iDoc);
        if(height < 600){
            height = 600;
        }
        ifr.style.height = (height+50) + 'px';
    }
	
});


//每次刷新页面都会清除保存数据
function startAdmin(){
	var userToken=localStorage.getItem("userToken");
	// alert(userToken);
	if(userToken==null){
		location.href="login.html";
		return; 
	}
    localStorage.setItem("admin_child_id","21");
    localStorage.setItem("admin_id","1");
    $("#com_info_li1").addClass("choose");
}
// 计算页面的实际高度，iframe自适应会用到
function calcPageHeight(doc) {
    var cHeight = Math.max(doc.body.clientHeight, doc.documentElement.clientHeight);
    var sHeight = Math.max(doc.body.scrollHeight, doc.documentElement.scrollHeight);
    var height  = Math.max(cHeight, sHeight);
    return height;  
}
//左侧的点击事件
function admin_info(id){
    var choose_id=localStorage.getItem("admin_id");
    var key=JSON.parse(choose_id);
    //alert(key);
    if(key=="" || key==null){
        choose_id=0;
    }
    if(choose_id>0){
        $("#com_info_li"+choose_id).removeClass("choose");
    }
    $("#com_info_li"+id).addClass("choose");
    localStorage.setItem("admin_id",id);
    if(choose_id==2 || choose_id==3 || choose_id==4 || choose_id==5 || choose_id==6 || choose_id==7){
        $('#com_info_div'+choose_id).css('display', 'none');
    }
	//给顶部显示的标题赋值
	var name=$('#com_info_li'+id).text();
	$('#title').text(name);
	$('#title_child').text("");
	
	// alert(name);
    switch(id){
        case 2:
        case 3:
        case 4:
        case 5:
        case 6:
		case 7:
            //关闭状态时，需要展示子模块,并且为选中状态
            if ($('#com_info_div'+id).css('display') == 'none') {
                $('#com_info_div'+id).css('display', 'block');
            }
            //展开状态
            else {
                $('#com_info_div'+id).css('display', 'none');
            }
            break;
    }
	//子项选中清空
	 // localStorage.setItem("admin_child_id","");
}
//左侧的子点击事件
function admin_info_child(id){
    //alert(id);
    //之前保存上次的选项修改为普通样式(要先删除原来的样式，再重新添加新的样式)
    var choose_id=localStorage.getItem("admin_child_id");
    var key=JSON.parse(choose_id);
    // alert("id："+id+"上次保存："+key);
    if(key=="" || key==null){
        choose_id=0;
    }
    $("#admin_info"+choose_id).removeClass("com_txt_choose");
    $("#admin_info"+choose_id).addClass("com_txt");

    $("#admin_info"+id).removeClass("com_txt");
    $("#admin_info"+id).addClass("com_txt_choose");
    localStorage.setItem("admin_child_id",id);
	//给顶部显示的标题赋值
	var name=$('#admin_info'+id).text();
	$('#title_child').text(">"+name);
	//费用设置数据清空
	if(id==74){
		localStorage.setItem("overtimeDepartId","");
		localStorage.setItem("chooseDays1","");
		localStorage.setItem("chooseDays2","");
		localStorage.setItem("chooseDays3","");	
		localStorage.setItem("overtime","");	
	}
}

$(function () {
    //通知功能
    $('#notice').click(function () {
        layui.use(['element', 'layer'], function() {
            var layer = layui.layer;
            layer.alert("消息通知！", {icon: 6});
        });
    });
	//设置功能
	$('#set').click(function () {
	    layui.use(['element', 'layer'], function() {
	        var layer = layui.layer;
	        layer.alert("设置！", {icon: 6});
	    });
	});
	//退出功能
	$('#quit').click(function () {
	    layui.use(['element', 'layer'], function() {
	        var layer = layui.layer;
			var userPhone=localStorage.getItem("userPhone");
			var userPwd=localStorage.getItem("userPwd");
			localStorage.clear();
			localStorage.setItem("userPhone",userPhone);
			localStorage.setItem("userPwd",userPwd);
			location.href="login.html";
	        // layer.alert("退出！", {icon: 6});
	    });
	});
	//数据编辑功能
	$('#edit').click(function () {
	    layui.use(['element', 'layer'], function() {
	        var layer = layui.layer;
	        layer.alert("编辑！", {icon: 6});
	    });
	});
	//删除功能
	$('#delete').click(function () {
	    layui.use(['element', 'layer'], function() {
	        var layer = layui.layer;
	        layer.alert("删除！", {icon: 6});
	    });
	});
});